package com.xinnet.mms.product.dao.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.xinnet.core.dao.impl.BaseDaoImpl;
import com.xinnet.mms.customtransfer.service.NewRegisterCustomTransferService;
import com.xinnet.mms.entity.Dept;
import com.xinnet.mms.entity.Product;
import com.xinnet.mms.product.dao.ProductDao;
@Repository("productDao")
public class ProductDaoImpl extends BaseDaoImpl<Product,Long> implements ProductDao{

	@Override
	public List<Product> queryEnableProduct() {
		List<Product> products = super.getSqlSession().selectList("product.queryEnableProduct");
		if(products==null || products.size()==0){
			products = null;
		}
		return products;
	}
	
	public void delTransferRuleByProductName(String productName){
		super.getSqlSession().delete("product.delTransferRuleByProductName",productName);
	}
	
	public void addProduct(Product product){
		super.getSqlSession().insert("product.addProduct",product);
	}
	
	public void updateSingleRate(Double singleRate){
		super.getSqlSession().update("product.updateSingleRate",singleRate);
	}
	
	public void updateProduct(Product product){
		super.getSqlSession().update("product.updateProduct",product);
	}
	public List<Product> getALLProduct(){
		List<Product> products = super.getSqlSession().selectList("product.getALLProduct");
		if(products==null || products.size()==0){
			products = null;
		}
		return products;
	}

	/**
	 * 根据产品id集合查询部门负责产品
	 */
	@Override
	public List<Product> getProductListByDeptno(Dept dept) throws SQLException {
		return this.getSqlSession().selectList("product.getProductListByDeptno",dept);
	}
	
	/**
	 * 
	 * @return String productId
	 */
	public Map<String,Product> getEnableProduct(){
		Map<String,Product> productRuleMap = new HashMap<String, Product>();
		List<Product> products = super.getSqlSession().selectList("product.queryEnableProduct");
		if(products==null || products.size()==0){
			products = null;
		}
		for (Iterator<Product> iterator = products.iterator(); iterator.hasNext();) {
			Product product = (Product) iterator.next();
			String productId= product.getId();
			productRuleMap.put(productId, product);
		}
		return productRuleMap;
	}

}
